package ascript.utilities
{
	//#########################
	// Header Includes
	//#########################
	import flash.media.SoundChannel;
	
	//#########################
	// SoundChannelQueued Class
	//#########################
	public class SoundChannelQueued
	{
		//=========================
		// Variables
		//=========================
		// Protected
		protected var channel:SoundChannel;
		protected var channelTemplate:SoundTemplate;
		protected var channelPausePosition:Number;

		//=========================
		// Initialization
		//=========================	
		public function SoundChannelQueued():void
		{
		}

		//=========================
		// Toggle
		//=========================
		public function stopChannel():void
		{
			channelTemplate = null;
			channel.stop();
		}
		
		public function playChannel( tSound:SoundTemplate )
		{
			channelTemplate = tSound;
			channel = tSound.sound.play();
			channel.soundTransform.volume = tSound.volume;
		}
		
		public function setPauseChannel( tIsPaused:Boolean ):void
		{
			if ( tIsPaused )
			{
				// Store pause position and stop
				channelPausePosition = channel.position;
				channel.stop();
			}
			else
			{
				// Play at position and reset volume
				channel = channelTemplate.sound.play( channelPausePosition );
				channel.soundTransform.volume = channelTemplate.volume;
			}
		}
	}
}